package com.leejie.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginMVCConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //将拦截器组件添加到容器中
        //拦截器默认会把静态资源也拦截下来，所以我们需要把静态资源的路径开放；必然还有我们登录页面路径
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/index","/impExcel","/expExcel","/upload","/css/**", "/js/**", "/img/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        System.out.println("访问/index路径会来到这里吗？");
        registry.addViewController("/index").setViewName("index");
    }
}
